<?php

namespace App\Http\Controllers\Admin;

use App\Models\Comment as CommentModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class Comment extends Controller
{
    //评论列表
    public function all()
    {
        $comments = CommentModel::with('articles', 'members')->orderBy('created_at', 'desc')->paginate(10);
        $viewData = [
            'comments' => $comments
        ];
        return view('admin.comment.list', $viewData);
    }

    //评论删除
    public function del()
    {
        $commentInfo = CommentModel::find(request('id'));
        $result = $commentInfo->delete();
        if ($result) {
            $msg = [
                'code' => 1,
                'msg' => '删除成功',
                'url' => url('admin/commentlist')
            ];
        }else {
            $msg = [
                'code' => 0,
                'msg' => '删除失败'
            ];
        }
        return $msg;
    }
}
